package com.example.administrator.exkotlin.activity

import android.os.Bundle
import android.util.Log
import com.example.administrator.exkotlin.R
import kotlinx.android.synthetic.main.activity_life.*

class LifeActivity : BaseActivity() {

    private val TAG = "LifeActivity"
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_life)
        reviewData(savedInstanceState)
        initData()
    }

    private fun initData() {
        btn_remove.setOnClickListener {
            Log.i(TAG, "removeActivity")
            ActivityCollector.removeActivity(this)
        }
        btn_quilt.setOnClickListener {
            Log.i(TAG, "Quilt")
            ActivityCollector.Quilt()
        }
    }


    //被回收之前一定会执行的保存信息
    override fun onSaveInstanceState(outState: Bundle?) {
        super.onSaveInstanceState(outState)
        outState?.putString("save_state", "临时保存${System.currentTimeMillis()}")
    }

    //回复数据
    private fun reviewData(savedInstanceState: Bundle?) {
        if (savedInstanceState != null) {
            val string: String = savedInstanceState.getString("save_state")
            Log.i(TAG, "恢复数据 $string")
        }
    }


}
